package com.fortune.cat.resolver;

import com.fortune.cat.bean.RequestRateLimiterConfig;
import com.fortune.cat.enums.RateLimiterKeyResolverEnums;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;

/**
 * @author zhaozeyang
 * @date 2019/4/26 11:41
 * @description
 */
@Component
public class QueryKeyResolver extends AbstractKeyResolver {


    @Override
    public Integer getType() {
        return RateLimiterKeyResolverEnums.QUERY.getType();
    }

    @Override
    protected String doResolve(ServerWebExchange exchange) {
        RequestRateLimiterConfig.Query query = requestRateLimiterConfig.getQuery();
        if (query.getValue().equals(exchange.getRequest().getQueryParams().getFirst(query.getQuery()))) {
            return query.getQuery().concat("-").concat(query.getValue());
        }
        return null;
    }


}
